package com.longlong.yfbank.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.longlong.yfbank.entity.dto.SearchPageInfo;
import com.longlong.yfbank.service.TraderecordService;
import com.longlong.yfbank.utils.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author longlong
 * @date 2024-01-06 16:46
 * description
 */
@RestController
@CrossOrigin
@RequestMapping("/tradecorde")
public class TradecordeController {

    @Resource
    private TraderecordService traderecordService;

    @GetMapping()
    public Page getTradeCordeAll(SearchPageInfo searchPageInfo){
        Page tradePage = new Page(searchPageInfo.getCurrentPage(), searchPageInfo.getPageSize());
        String typeId = searchPageInfo.getTypeId();
        DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
        // 使用DateTimeFormatter解析ISO 8601字符串
        LocalDateTime localStartDateTime = LocalDateTime.parse(searchPageInfo.getStartTime(), formatter);
        LocalDateTime localEndDateTime = LocalDateTime.parse(searchPageInfo.getEndTime(), formatter);
        // 使用DateTimeFormatter解析ISO 8601字符串
        ZonedDateTime zonedStartDateTime = ZonedDateTime.parse(searchPageInfo.getStartTime(), formatter);
        ZonedDateTime zonedEndDateTime = ZonedDateTime.parse(searchPageInfo.getEndTime(), formatter);
        return traderecordService.findAll(tradePage,typeId,localStartDateTime,localEndDateTime);

    }
}
